<template>
  <div>
    <el-select v-model="provinceQueryParams.pid" placeholder="请选择" @change="selectChange" clearable>
      <el-option v-for="item in provinceOptions" :key="item.id" :label="item.name" :value="item.id">
      </el-option>
    </el-select>
    <el-select v-model="cityQueryParams.pid" placeholder="请选择" clearable>
      <el-option v-for="item in cityOptions" :key="item.id" :label="item.name" :value="item.id">
      </el-option>
    </el-select>
  </div>
</template>
  
  <script>
import { listChina } from "@/api/part/china";
export default {
  data() {
    return {
      provinceOptions: [],
      cityOptions: [],
      provinceQueryParams: {
        id: "",
        name: "",
        pid: "",
      },
      cityQueryParams: {
        id: "",
        name: "",
        pid: "",
      },
    };
  },
  //生命周期函数，组件创建后
  created() {
    this.getList();
  },
  methods: {
    getList() {
      listChina(this.provinceQueryParams).then((response) => {
        this.provinceOptions = response.rows;
      });
    },
    selectChange() {
      //清空下拉框里面选择的内容
      this.cityQueryParams.pid = "";
      //清空下拉框里面option的内容
      //this.cityOptions = [];
      listChina(this.provinceQueryParams).then((response) => {
        this.cityOptions = response.rows;
      });
    },
  },
};
</script>